/**
Date:20220321 22:22 PM
key:1.先中序遍历得到vector，然后再经典比较
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool F1(vector<int>&v,int target)
    {
        int i=0,j=v.size()-1;
        while(i<j)
        {
            if(v[i]+v[j]==target)
            {
                return true;
            }else
            {
                if(v[i]+v[j]>target){
                    j--;
                }else{
                    i++;
                }
            }
        }
        return false;
    }
    void MidVis(TreeNode* root,vector<int>&v)
    {
        if(root!=nullptr)
        {
            MidVis(root->left,v);
            v.push_back(root->val);
            MidVis(root->right,v);
        }
    }
    bool findTarget(TreeNode* root, int k) {
        vector<int>v;
        MidVis(root,v);
        //for(int t:v){cout<<t<<" ";}
        return F1(v,k);
    }
};